package com.jiayan.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayan.mapper.EbProductCategoryMapper;
import com.jiayan.mapper.EbProductMapper;
import com.jiayan.model.EbProduct;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Wrapper;
import java.util.HashMap;
import java.util.Map;

@Service
public class ProductService {
    @Resource
    private EbProductMapper ebProductMapper;


    public EbProduct detail(Integer pid){
        EbProduct ebProduct = ebProductMapper.selectById(pid);
        return ebProduct;
    }

    public Map<String, Object> list(int pnum) {
        Map<String, Object> result = new HashMap();
        //TODO 1.分页查询商品数据  默认第1页 每页8条数据
        Page<EbProduct> page = new Page<>(pnum, 10);
        Page<EbProduct> productPage = ebProductMapper.selectPage(page, null);
        //将数据封装的到Map集合
        result.put("productPage", productPage);
        return result;

    }

    /*@Resource
    private EbProductCategoryMapper ebProductCategoryMapper;
*/
    public Page search(String keyword,Integer pnum){
        Page page =new Page(pnum,2);
        Page productPage=ebProductMapper.selectPage(page, Wrappers.<EbProduct>lambdaQuery()
                        .like(EbProduct::getEpName,keyword));
        if(productPage==null){
            System.out.println("商品不存在");
        }
        return productPage;
    }
}
